#!/bin/bash
#Blog init script
#Version: 1.0
echo "Blog init script"

echo "1.1 remove old blog"
rm -rf /usr/sid2656

echo "2.2 copy new blog home"
git clone https://gitee.com/sid2656/sid2656.github.io.git /usr/sid2656

echo "2.1 copy new blog index"
git clone https://gitee.com/sid2656/sid2656pics.github.io.git /usr/sid2656/files

echo "2.2 copy new blog files"
git clone https://gitee.com/sid2656/parentBJ.git /usr/sid2656/parentBJ


echo "3.1 replace url :2017before"
# 读取原始URL和新URL

# 获取要处理的文件列表
files=$(find /usr/sid2656/ -type f \( -iname \*.txt -o -iname \*.html -o -iname \*.php \))

# 遍历文件列表并替换URL
for file in $files; do
  if [ -d "$file" ]; then
    echo "$file is a directory "
  elif [ -f "$file" ]; then
    sed -i 's/http:\/\/files.sid2656.space\/2017before/https:\/\/imgs.sid2656.life\/2017before/g' "$file"
  fi
done

echo "2017before URL替换完成！"

echo "3.2 replace url :landscape"
# 读取原始URL和新URL

# 获取要处理的文件列表
files=$(find /usr/sid2656/ -type f \( -iname \*.txt -o -iname \*.html -o -iname \*.php \))

# 遍历文件列表并替换URL
for file in $files; do
  if [ -d "$file" ]; then
    echo "$file is a directory "
  elif [ -f "$file" ]; then
    sed -i 's/http:\/\/files.sid2656.space\/landscape/https:\/\/imgs.sid2656.life\/landscape/g' "$file"
  fi
done

echo "landscape URL替换完成！"

echo "3.3 replace url :318ride"
# 读取原始URL和新URL

# 获取要处理的文件列表
files=$(find /usr/sid2656/ -type f \( -iname \*.txt -o -iname \*.html -o -iname \*.php \))

# 遍历文件列表并替换URL
for file in $files; do
  if [ -d "$file" ]; then
    echo "$file is a directory "
  elif [ -f "$file" ]; then
    sed -i 's/http:\/\/files.sid2656.space\/318ride/https:\/\/imgs.sid2656.life\/318ride/g' "$file"
  fi
done

echo "318ride URL替换完成！"

echo "3.4 replace url :AI"
# 读取原始URL和新URL

# 获取要处理的文件列表
files=$(find /usr/sid2656/ -type f \( -iname \*.txt -o -iname \*.html -o -iname \*.php \))

# 遍历文件列表并替换URL
for file in $files; do
  if [ -d "$file" ]; then
    echo "$file is a directory "
  elif [ -f "$file" ]; then
    sed -i 's/http:\/\/files.sid2656.space\/AI/https:\/\/imgs.sid2656.life\/AI/g' "$file"
  fi
done

echo "AI URL替换完成！"

echo "3.5 replace url :lifes"
# 读取原始URL和新URL

# 获取要处理的文件列表
files=$(find /usr/sid2656/ -type f \( -iname \*.txt -o -iname \*.html -o -iname \*.php \))

# 遍历文件列表并替换URL
for file in $files; do
  if [ -d "$file" ]; then
    echo "$file is a directory "
  elif [ -f "$file" ]; then
    sed -i 's/http:\/\/files.sid2656.space\/lifes/https:\/\/imgs.sid2656.life\/lifes/g' "$file"
  fi
done

echo "lifes URL替换完成！"

echo "3.6 replace url :persons"
# 读取原始URL和新URL

# 获取要处理的文件列表
files=$(find /usr/sid2656/ -type f \( -iname \*.txt -o -iname \*.html -o -iname \*.php \))

# 遍历文件列表并替换URL
for file in $files; do
  if [ -d "$file" ]; then
    echo "$file is a directory "
  elif [ -f "$file" ]; then
    sed -i 's/http:\/\/files.sid2656.space\/persons/https:\/\/imgs.sid2656.life\/persons/g' "$file"
  fi
done

echo "persons URL替换完成！"

echo "3.7 replace url :parentBJ"
# 读取原始URL和新URL

# 获取要处理的文件列表
files=$(find /usr/sid2656/ -type f \( -iname \*.txt -o -iname \*.html -o -iname \*.php \))

# 遍历文件列表并替换URL
for file in $files; do
  if [ -d "$file" ]; then
    echo "$file is a directory "
  elif [ -f "$file" ]; then
    sed -i 's/http:\/\/files.sid2656.space\/parentBJ/https:\/\/imgs.sid2656.life\/parentBJ/g' "$file"
  fi
done

echo "parentBJ URL替换完成！"

echo "3.8 replace url :experience"
# 读取原始URL和新URL

# 获取要处理的文件列表
files=$(find /usr/sid2656/ -type f \( -iname \*.txt -o -iname \*.html -o -iname \*.php \))

# 遍历文件列表并替换URL
for file in $files; do
  if [ -d "$file" ]; then
    echo "$file is a directory "
  elif [ -f "$file" ]; then
    sed -i 's/http:\/\/files.sid2656.space\/experience/https:\/\/imgs.sid2656.life\/experience/g' "$file"
  fi
done

echo "experience URL替换完成！"

echo "3.9 replace url :tech"
# 读取原始URL和新URL

# 获取要处理的文件列表
files=$(find /usr/sid2656/ -type f \( -iname \*.txt -o -iname \*.html -o -iname \*.php \))

# 遍历文件列表并替换URL
for file in $files; do
  if [ -d "$file" ]; then
    echo "$file is a directory "
  elif [ -f "$file" ]; then
    sed -i 's/http:\/\/files.sid2656.space\/tech/https:\/\/imgs.sid2656.life\/tech/g' "$file"
  fi
done

echo "tech URL替换完成！"


echo "3.10 replace url :files"
# 读取原始URL和新URL

# 获取要处理的文件列表
files=$(find /usr/sid2656/ -type f \( -iname \*.txt -o -iname \*.html -o -iname \*.php \))

# 遍历文件列表并替换URL
for file in $files; do
  if [ -d "$file" ]; then
    echo "$file is a directory "
  elif [ -f "$file" ]; then
    sed -i 's/https:\/\/files.sid2656.space/https:\/\/sid2656.life/g' "$file"
  fi
done

echo "files URL替换完成！"
echo "3.11 replace url :space"
# 读取原始URL和新URL

# 获取要处理的文件列表
files=$(find /usr/sid2656/ -type f \( -iname \*.txt -o -iname \*.html -o -iname \*.php \))

# 遍历文件列表并替换URL
for file in $files; do
  if [ -d "$file" ]; then
    echo "$file is a directory "
  elif [ -f "$file" ]; then
    sed -i 's/sid2656.space/sid2656.life/g' "$file"
  fi
done

echo "space URL替换完成！"


echo "4. replace filetype :JPG"
# 读取原始URL和新URL

# 获取要处理的文件列表
files=$(find /usr/sid2656/ -type f \( -iname \*.txt -o -iname \*.html -o -iname \*.php \))

# 遍历文件列表并替换URL
for file in $files; do
  if [ -d "$file" ]; then
    echo "$file is a directory "
  elif [ -f "$file" ]; then
    sed -i 's/.JPG/.jpg/g' "$file"
  fi
done

echo "space URL替换完成！"


echo "4. rename fileName :JPG"
# 读取原始URL和新URL

# 获取要处理的文件列表
files=$(find /usr/sid2656/ -type f \( -iname \*.JPG \))

for file in $files; do
    if [[ -f "$file" ]]; then
        base=${file%.*}
        new_name="$base.jpg"
        mv "$file" "$new_name"
    fi
done


echo "space URL替换完成！"

echo "Blog init script finish!"